package com.youzi.redis.client;

import java.util.Set;

import org.apache.commons.lang3.StringUtils;

import redis.clients.jedis.Jedis;

public class RedisClient {

	static Jedis jedis;

	static {
		jedis = new Jedis(RedisConfig.host, RedisConfig.port);

		String password = RedisConfig.password;
		if (StringUtils.isNotEmpty(password)) {
			jedis.auth(password);
		}
	}

	public static void delByPattern(String pattern) {
		Set<String> keys = jedis.keys(pattern);
		if (keys == null || keys.isEmpty()) {
			return;
		}
		String[] strs = new String[keys.size()];
		keys.toArray(strs);
		System.out.println(strs);
		jedis.del(strs);
	}

	public static void del(String... keys) {
		jedis.del(keys);
	}

	public static Set<String> keys(String pattern) {
		return jedis.keys(pattern);
	}

}
